#include "log.h"
#include <stdio.h>
#include <stdarg.h>



int g_current_dbg_level = LOG_LEVEL_DEBUG;
char msg_buf[LOG_FORMAT_SIZE];

uint32_t log_GetTime(void)
{
    uint32_t tick = HAL_GetTick();
    return tick;
}

void log_fun(int level, const char *opt, const char *tag, int line, const char *func, const char *fmt, ...)
{
    if (level < g_current_dbg_level)
    {
        return;
    }
        va_list ap;
        va_start(ap, fmt);
        int len = snprintf(msg_buf, LOG_FORMAT_SIZE, "[%d]%s/%s/%d/%s(): ",log_GetTime(), opt, tag, line, func);
        len += vsnprintf(msg_buf + len, LOG_FORMAT_SIZE - len, fmt, ap);
        LOGN(msg_buf, len);
        va_end(ap);
}


/* 设置 打印级别 */
void log_set_level(int level)
{
    g_current_dbg_level = level;
}
